﻿

@model PagedList<Views_Goods>
@{
    ViewBag.Title = "在售物料列表";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    ProductListQueryModel paramModel = new ProductListQueryModel();
    if (ViewBag.paramModel != null)
    {
        paramModel = (ProductListQueryModel)ViewBag.paramModel;
    }
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
    Dictionary<string, string> labelDicTypeName = ReleaseBiz.GetLabelTypeNameDic();

}
<form id="S_Form" class="S_Form form-inline definewidth m20" action="@Url.Action("productlist", "product")" method="get">
    <div class="form_query">
        <div>
            编号：
            <input type="text" name="goods_id" id="goods_id" class="abc input-default" placeholder="" value="@paramModel.goods_id">&nbsp;
        </div>
        <div>
            料号：
            <input type="text" name="MPN" id="MPN" class="abc input-default" placeholder="" value="@paramModel.MPN">&nbsp;
        </div><div>
            板块：
            <select id="label_type" name="label_type">
                <option value="-10" @(paramModel.label_type == -10 ? "selected" : "")>全部板块</option>
                @{
                    dc = labelDicTypeName;
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.label_type.ToString());
            </select>&nbsp;
        </div><div>
    结束时间：
    <input type="text" name="end_time_begin" class="calendar calendar-time" id="end_time_begin" value="@paramModel.end_time_begin.ToString(1)"> - <input type="text" name="end_time_end" class="calendar calendar-time" id="end_time_end" value="@paramModel.end_time_end.ToString(1)">&nbsp;
    <div>
        <info style="float:left;">品牌：&nbsp;</info>
        <div id="brand_id_name"></div>&nbsp;
        <script>
                BUI.use('bui/select', function (Select) {
                    $.post('@Url.Action("getbrands", "common")', {  }, function (result) {
                        var suggest = new Select.Suggest({
                            render: '#brand_id_name',
                            name: 'brand_id_name',
                            data: result
                        });
                        suggest.render();
                        $("input[name='brand_id_name']").val('@paramModel.brand_id_name');
                        $("input[name='brand_id_name']").attr("autocomplete", "off");
                    });
                });
        </script>
    </div> <div>
        分类：
        <select id="category_id" name="category_id">
            <option value="-10">全部分类</option>
            @{
                dc = new Dictionary<string, string>();
                ADZ_GoodsCategoryBiz.Instance.GetParentSunList().ForEach(t =>
                {
                    dc.Add(t.category_id.ToString(), t.category_name);
                });
            }
            @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.category_id.ToString())
        </select>&nbsp;
    </div>
    <div>
        <info style="float:left;">供应商：&nbsp;</info>
        <div id="supplier_id_name"></div>&nbsp;
        <script>
                BUI.use('bui/select', function (Select) {
                    $.post('@Url.Action("getsuppliers", "common")', {  }, function (result) {
                        var suggest = new Select.Suggest({
                            render: '#supplier_id_name',
                            name: 'supplier_id_name',
                            data: result
                        });
                        suggest.render();
                        $("input[name='supplier_id_name']").val('@paramModel.supplier_id_name');
                        $("input[name='supplier_id_name']").attr("autocomplete", "off");
                    });
                });
        </script>
    </div><div>
        是否上架：
        <select id="is_withdraw" name="is_withdraw">
            <option value="-10">全部</option>
            @{
                dc = new Dictionary<string, string>();
                dc.Add("0", "已上架");
                dc.Add("1", "已下架");
            }
            @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.is_withdraw.ToString());
        </select>&nbsp;
    </div><div>
        是否有库存：
        <select id="stock_amount" name="stock_amount">
            <option value="-10">全部</option>
            @{
                dc = new Dictionary<string, string>();
                dc.Add("0", "没库存");
                dc.Add("1", "库存不足");
                dc.Add("2", "库存充足");
            }
            @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.stock_amount.ToString());
        </select>&nbsp;
    </div><div>
        上架时间：
        <input type="text" name="with_up_time_begin" class="calendar calendar-time" id="with_up_time_begin" value="@paramModel.with_up_time_begin.ToString(1)"> - <input type="text" name="with_up_time_end" class="calendar calendar-time" id="with_up_time_end" value="@paramModel.with_up_time_end.ToString(1)">&nbsp;
    </div>
    <div>
        下架时间：
        <input type="text" name="with_down_time_begin" class="calendar calendar-time" id="with_down_time_begin" value="@paramModel.with_down_time_begin.ToString(1)"> - <input type="text" name="with_down_time_end" class="calendar calendar-time" id="with_down_time_end" value="@paramModel.with_down_time_end.ToString(1)">&nbsp;
    </div>
    <div>
        下架原因：
        <input type="text" name="draw_down_reason" id="draw_down_reason" class="abc input-default" placeholder="" value="@paramModel.draw_down_reason">&nbsp;
    </div>
    <div>
        @{Html.RenderPartial(Url.Content("~/Views/Common/PageSize.cshtml"), paramModel);}
    </div><div>
        <button type="submit" class="btn btn-primary" id="formsubmit">查询</button>&nbsp;&nbsp; <button type="button" class="btn btn-success" id="additemMore" onclick="document.location='@Url.Action("addMoreTempProduct","TempProduct")'">批量添加</button>
        &nbsp;&nbsp;<button type="button" class="btn btn-primary" id="downloadexcel">下载表格</button>

    </div>
</div>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th style="width:40px">
                <input type="checkbox" name="chkall" id="chkall" />全选
            </th>
            <th style="width:65px">图片</th>
            <th>料号</th>
            <th>品牌</th>
            <th>分类</th>
            <th>供应商</th>
            <th>物料来源</th>
            <th>板块</th>
            <th>板块信息</th>
            <th>普通会员可看</th>
            <th>结束时间</th>
            <th>单位</th>
            <th>DC号</th>
            <th>库存数量</th>
            <th>最小订购量</th>
            <th>上传价格</th>
            <th>币种</th>
            <th>供货价</th>
            <th>市场价</th>
            <th>是否含税</th>
            <th>上架时间</th>
            <th>下架时间</th>
            <th>是否上架</th>
            <th>下架原因</th>
            <th>操作</th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
    {
        int index = 0;
        foreach (var m in Model)
        {
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                <td>
                    <input type="checkbox" name="cbx_last" value="@m.goods_id" />@m.goods_id
                </td>
                <td style="padding:5px 0 0 2px;">
                    @{
                        var aDZ_GoodsIMGs = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == m.goods_id).OrderBy(t => t.sort_NO).ThenBy(t => t.seq_id);
                        foreach (var item in aDZ_GoodsIMGs.OrderBy(t => t.sort_NO))
                        {
                            <a class="list-img" href="@ImageFileBiz.GetImg(item.img_url)" target="_blank"> <img style="width:30px;margin:1px 1px 1px 1px;" src="@ImageFileBiz.GetImg(item.img_url,"small")" /></a>
                        }
                    }
                </td>
                <td>@m.MPN</td>
                <td>@m.brand_name</td>
                <td>@m.category_name</td>
                <td>@m.supplier_name</td>
                <td>@m.material_source_name</td>
                <td>
                    <div class="">@labelDicTypeName[m.label_type.ToString()]</div>
                </td>
                <td>
                    @switch (m.label_type)
                    {
                        case (int)(LabelType.YuRe):
                            if (!(m.price > 0))
                            {
                                int counts = dbcontext.View_OrderPlace.Where(t => t.goods_id == m.goods_id).Count();
                                <a class="opennewtab_del" href="@Url.Action("OrderPlaceList", "OrderPlace", new { goods_id = m.goods_id,is_del=-10})">查看报价[@counts]</a>
                            }
                            break;
                        case (int)(LabelType.Jingjia):
                            var jingjia_info = dbcontext.ADZ_GoodsJingjia.FirstOrDefault(t => t.goods_id == m.goods_id);
                            if (jingjia_info != null && jingjia_info.jingjia_id > 0)
                            {
                                @jingjia_info.jingjia_id <a href="/jingjia/add/@jingjia_info.jingjia_id">查看竞价信息</a>
                            }
                            else
                            {
                                <info class="red">还未加到竞价包中</info>
                            }
                            break;
                        case (int)(LabelType.Huodong):
                            var huodong_info = dbcontext.ADZ_GoodsHuodong.FirstOrDefault(t => t.goods_id == m.goods_id);
                            if (huodong_info != null && huodong_info.huodong_id > 0)
                            {
                                @huodong_info.huodong_id <a href="/huodong/add/@huodong_info.huodong_id">查看活动信息</a>
                            }
                            else
                            {
                                <info class="red">还未加到活动中</info>
                            }
                            break;
                        default:
                            @:<div class="">--</div>
                            break;
                    }
                </td>
                <td>
                    @if (m.base_label_type == 1)
                    {
                        if (m.show_min_level == 0)
                        {
                            @:<div class="green">可看 <a href="javascript:void(0);" onclick="setshow_min_level(@m.goods_id,1)">设为不可看</a></div>
                        }
                        else
                        {
                            @:<div class="red">不可看 <a href="javascript:void(0);" onclick="setshow_min_level(@m.goods_id,0)">设为可看</a></div>
                        }
                    }
                    else
                    {
                        <label>--</label>
                    }
                </td>
                <td>
                    @{
                        if (m.end_time.HasValue && m.end_time.Value < DateTime.Now)
                        {
                            <info class="red">已结束</info>
                        }
                        else
                        {
                            @m.end_time.ToString(1)
                        }
                    }
                </td>
                <td>@m.goods_unit</td>
                <td>@m.DCN</td>
                <td>@m.stock_amount</td>
                <td>@m.min_amount</td>
                <td>@m.price</td>
                <td>
                    @switch (m.currency_type)
                    {
                        case 0:
                            @:<div class="">人民币</div>
                            break;
                        case 1:
                            @:<div class="red">美金</div>
                            break;
                    }
                </td>
                <td>@m.supply_price</td>
                <td>@m.market_price</td>
                <td>
                    @switch (m.include_tax)
                    {
                        case 0:
                            @:<div class="">未含税</div>
                            break;
                        case 1:
                            @:<div class="green">含税</div>
                            break;
                    }
                </td>
                <td>@m.with_up_time.ToString(1)</td>
                <td>@m.with_down_time.ToString(1)</td>
                <td>
                    @switch (m.is_withdraw)
                    {
                        case 0:
                            @:<div class="green">已上架 <a href="@Url.Action("toWithdrawDown", "product", new { id = m.goods_id})">下架</a></div>
                            break;
                        case 1:
                            @:<div class="red">已下架 <a href="javascript:void(0);" onclick="toWithdrawUp(@m.goods_id)">上架</a></div>
                            break;
                    }
                </td>
                <td>@m.draw_down_reason</td>
                <td>
                    <a href="@Url.Action("detailInfo", "product", new { id = m.goods_id})">查看详情</a>

                </td>
            </tr>
        }
        <tr>
            <td colspan="20">
                <a href="javascript:void(0);" onclick="toWithdrawMore(0)">上架选择项</a>
                <a href="javascript:void(0);" onclick="toWithdrawMore(1)">下架选择项</a>
                <a href="javascript:void(0);" id="btn_changeLabel">调整频道</a>
                <a href="javascript:void(0);" id="btn_changeendtime">调整结束时间</a>
            </td>
        </tr>
    }
</table>
<div class="inline pull-left total">
    总行数：@ViewData["AllCount"]
</div>
<div class="inline pull-right page">
    @if (Model != null)
    {
        @Html.Pager(Model, HtmlPagerHelper.BasePagerOption)
    }
</div>

<style>
    #div_Mask {
        text-align: center;
        line-height: 100px;
        font-weight: bold
    }

    #J_Form {
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,.4);
        position: absolute;
        z-index: 1000;
        top: 0;
        left: 0;
        color: #000;
    }
</style>
<div id="div_Mask" class="hide">
    <form id="J_Form">
        <table class="table table-bordered definewidth m10 " style="width:600px;margin-top:200px;background-color:#fff">
            <tr>
                <th colspan="2">
                    批量下架商品
                </th>
            </tr>        
            <tr id="dvReason">
                <td class="tableleft">下架原因</td>
                <td>
                    <textarea id="txtreason" class="input-large"></textarea>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <button type="button" class="btn btn-primary" id="btn_saveexp">提交</button> &nbsp;&nbsp;
                    <button type="button" class="btn btn-success" id="btn_cancel">取消</button>
                </td>
            </tr>
        </table>
    </form>
</div>

<script>
    var cancelButton =
        {
            text: '取消',
            elCls: 'button',
            handler: function () {
                this.close();
            }
        };
    reloadHandler = function ()
    {
        window.location.reload();
    }
    function setshow_min_level(id, show_min_level) {
        var op_name = "不可看";
        if (show_min_level == 0) {
            op_name = "可看";
        }
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将该物料设为普通会员'+op_name+'吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("setshow_min_level", "product")";
                      parameter = {
                          id: id,
                          show_min_level: show_min_level
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    }

    function toWithdrawUp(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将该物料上架吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("toWithdrawUp", "product")";
                      parameter = { id: id };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    }

    $("#btn_cancel").click(function () {
        $("#div_Mask").hide();
    });
    $("#btn_saveexp").click(function () {
        url = "@Url.Action("toWithdrawMore", "product")";
        var ids = getCheckboxList();
        parameter = {
            withdraw: 1,
            ids: ids,
            reason: $("#txtreason").val()
        };
        $.post(url, parameter, function (result) {
            ShowActionResult(result, reloadHandler);
            $("#div_Mask").hide();
            this.close();
        });
    });


    function toWithdrawMore(withdraw) {
        var op_name = "下架";
        if (withdraw == 0) {
            op_name = "上架";
        }
        var ids = getCheckboxList();
        if (ids.length == 0) {
            BUI.Message.Alert("请选择要" + op_name+"的数据", 'warning');
            return;
        }
        if (withdraw != 0) {            
            $("#div_Mask").show();
            return;
        }

        BUI.Message.Show({
            title: '提示',
            msg: '确定要将选择的物料都' + op_name+'吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("toWithdrawMore", "product")";
                      parameter = {
                        withdraw: withdraw,
                        ids: ids
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
              },
                cancelButton

            ]
        });
    }

    //下载列表
    $("#formsubmit").on("click", function () {
        $("#S_Form").attr("action", "@Url.Action("productlist", "product")");
        $("#S_Form").submit();
    });

    //下载列表
    $("#downloadexcel").on("click", function () {
        $("#S_Form").attr("action", "@Url.Action("downProductlist", "product")");
        $("#S_Form").submit();
    });

</script>

<script>

    BUI.use('bui/overlay', function (Overlay) {

        function dochangelabel() {
            var label_type = ($("#select_label_type").val());
            if (label_type == 0) {
                BUI.Message.Alert("请选择要修改的板块", 'warning');
                return false;
            }
            var ids = getCheckboxList();
            if (ids.length == 0) {
                BUI.Message.Alert("请选择要修改的数据", 'warning');
                return false;
            }

            url = "@Url.Action("ChangeLabelMore", "product")";
            parameter = {
                ids: ids,
                label_type: label_type
            };
            $.post(url, parameter, function (result) {
                ShowActionResult(result, reloadHandler);
            });
        }
        var dialog = new Overlay.Dialog({
            title: '修改板块',
            width: 600,
            height: 300,
            buttons: [
                {
                    text: '确定',
                    elCls: 'button button-primary',
                    handler: function () {
                        if (dochangelabel()) {
                            this.close();
                        }
                    }
                },
                cancelButton
            ],
            bodyContent:
                '<div id="div_changelabel" >' +
                '    <table class="table table-bordered definewidth m10 ">    ' +
                '        </tr>                                                                                                           ' +
                '        <tr>                                                                                                            ' +
                '            <td style="text-align:right">                                                                               ' +
                '                板块信息：                                                                                              ' +
                '    </td>                                                                                                               ' +
                '            <td>                                                                                                        ' +
                '                <select name="select_label_type" id="select_label_type">                                                                              ' +
                '                    <option value="0">请选择</option>                                                                   ' +
                @{
                    var lablllist = dbcontext.ADZ_LabelConfig.OrderBy(t => t.sort_id).ToList();
                    for(int i=0;i< lablllist.Count();i++)
                    {
                        var t = lablllist[i];
                        if(t.base_label_type == 1 || t.base_label_type == 2 || t.base_label_type == 3)
                        {
                            @:'<option value=\"@(t.label_type)\">@(t.label_name)</option>' +
                        }
                    }
                }
                '                </select>                                                                                               ' +
                '            </td>                                                                                                       ' +
                '        </tr>                                                                                                           ' +
                '    </table>                                                                                                            ' +
                '</div >'
        });

        $('#btn_changeLabel').on('click', function (e) {
            var ids = getCheckboxList();
            if (ids.length == 0) {
                BUI.Message.Alert("请选择要修改的数据", 'warning');
                return;
            }
            e.preventDefault();
            dialog.show();
        });
    });

</script>



<script>

    BUI.use(['bui/form', 'bui/overlay'], function (Form, Overlay) {

        function dochangeEndtime() {
            var endtime = ($("#txt_endtime").val());
            if (endtime == null) {
                BUI.Message.Alert("请输入正确的时间", 'warning');
                return false;
            }
            var ids = getCheckboxList();
            if (ids.length == 0) {
                BUI.Message.Alert("请选择要修改的数据", 'warning');
                return false;
            }

            url = "@Url.Action("ChangeEndtimeMore", "product")";
            parameter = {
                ids: ids,
                endtime: endtime
            };
            $.post(url, parameter, function (result) {
                ShowActionResult(result, reloadHandler);
            });
        }
        var dialog_endtime = new Overlay.Dialog({
            title: '修改结束时间',
            width: 600,
            height: 300,
            buttons: [
                {
                    text: '确定',
                    elCls: 'button button-primary',
                    handler: function () {
                        if (dochangeEndtime()) {
                            this.close();
                        }
                    }
                },
                cancelButton
            ],
            bodyContent:
                '<form class="S_Form"><div id="div_changeendtime" >' +
                '    <table class="table table-bordered definewidth m10 ">    ' +
                '        </tr>                                                                                                           ' +
                '        <tr>                                                                                                            ' +
                '            <td style="text-align:right">                                                                               ' +
                '                结束时间：                                                                                              ' +
                '    </td>                                                                                                               ' +
                '            <td>                                                                                                        ' +
                '<input type="text" name="txt_endtime" class="calendar calendar-time" id="txt_endtime">'+
                '            </td>                                                                                                       ' +
                '        </tr>                                                                                                           ' +
                '    </table>                                                                                                            ' +
                '</div ></form>'
        });

        $('#btn_changeendtime').on('click', function (e) {
            var ids = getCheckboxList();
            if (ids.length == 0) {
                BUI.Message.Alert("请选择要修改的数据", 'warning');
                return;
            }
            e.preventDefault();
            dialog_endtime.show();

            new Form.Form({
                srcNode: '.S_Form'
            }).render();
        });

    });

</script>